package com.sheyu;

/**
 * @author sheyu
 * @date 2020/8/25 3:11 下午
 */
public class Index_88 {

    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        /**
         int[] nums = new int[m+n];
         int startN = 0,startM =0,i=0;
         while (startM<m&&startN<n){
         if (nums1[startM]<nums2[startN]){
         nums[i] = nums1[startM];
         startM+=1;
         }else{
         nums[i] = nums2[startN];
         startN+=1;
         }
         i+=1;
         }
         if (startM<m){
         for (int j = startM; j < m; j++) {
         nums[i] = nums1[j];
         i+=1;
         }
         }
         if (startN<n){
         for (int j = startN; j < n; j++) {
         nums[i] = nums2[j];
         i+=1;
         }
         }
         //nums1 = Arrays.copyOf(nums,m+n);*/
        int p1 = m-1;
        int p2 = n-1;
        int p = m+n-1;
        while(p1>=0&&p2>=0){
            nums1[p--] = nums1[p1]<nums2[p2]?nums2[p2--]:nums1[p1--];
        }
        System.arraycopy(nums2,0,nums1,0,p2+1);
    }
}
